home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ObjectHelpers.c
-
- Contains: Functions to help you when you are working with Apple event objects.
-
- Written by: Andy Bachorski
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/21/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- // Conditionals to setup the build environment the way we like it.
- #include "PrivateConditionals.h"
-
-
- //********** Universal Headers ****************************************
-
- #include <AERegistry.h>
- #include <AEObjects.h>
- #include <AEPackObject.h>
- #include <Aliases.h>
- #include <Icons.h>
- #include <Processes.h>
-
- #if UNIVERSAL_INTERFACES_VERSION >= 0x0300
- #include <FinderRegistry.h>
- #else
- #include "FinderRegistry.h"
- #endif
-
- //********** Project Headers ****************************************
-
- #include "ObjectHelpers.h"
- #include "AEHelpers.h"
-
-
- //********** Private Prototypes ****************************************
-
- static pascal OSErr MyIconAction( ResType theIconType,
- const Handle *theIcon,
- void *myDataPtr);
- /*
- Used by OHMakeIconFamilyRecord, passed to ForEachIconDo as the IconAction
- function. Puts each icon in an icon suite into the descriptor record passed
- in the myDataPtr parameter.
- */
-
- //******************************************************************************
-
- pascal OSErr OHAddAliasParameterFromFSS( const FSSpecPtr fssPtr,
- DescType keyword,
- AERecord *theRecordPtr )
- {
- OSErr anErr = noErr;
- AliasHandle aliasHandle;
-
- anErr = NewAlias( nil, fssPtr, &aliasHandle);
- if ( anErr == noErr && aliasHandle == nil )
- {
- anErr = paramErr;
- }
-
- if ( anErr == noErr )
- {
- char handleState;
-
- handleState = HGetState( (Handle)aliasHandle );
- HLock( (Handle)aliasHandle );
-
- anErr = AEPutParamPtr( theRecordPtr, keyword, typeAlias,
- *aliasHandle, (*aliasHandle)->aliasSize);
-
- HSetState( (Handle)aliasHandle, handleState );
- DisposeHandle( (Handle)aliasHandle );
- }
-
- return anErr;
- }//end AddAliasParameterFromFSS
-
- //******************************************************************************
-
- pascal OSErr OHMakeAliasDescFromFSSpec( const FSSpecPtr fssPtr,
- AEDesc *aliasDescPtr )
- {
- OSErr anErr = noErr;
- AliasHandle aliasHandle;
-
- anErr = NewAlias( nil, fssPtr, &aliasHandle);
- if ( anErr == noErr && aliasHandle == nil )
- {
- anErr = paramErr;
- }
-
- if ( anErr == noErr )
- {
- anErr = OHMakeAliasDesc( aliasHandle, aliasDescPtr );
- DisposeHandle( (Handle)aliasHandle );
- }
-
- return anErr;
- }//end MakeAliasObject
-
- //******************************************************************************
-
- pascal OSErr OHMakeAliasDesc( const AliasHandle aliasHandle,
- AEDesc *aliasDescPtr )
- {
- OSErr anErr = noErr;
-
- char handleState = HGetState( (Handle)aliasHandle );
- HLock( (Handle)aliasHandle );
-
- anErr = AECreateDesc( typeAlias, *aliasHandle, GetHandleSize( (Handle)aliasHandle ), aliasDescPtr );
-
- HSetState( (Handle)aliasHandle, handleState );
-
- return anErr;
- }//end MakeAliasObject
-
- //******************************************************************************
-
- pascal OSErr OHMakeAliasObjectFromFSSpec( const FSSpecPtr fssPtr,
- AEDesc *containerObjPtr,
- AEDesc *aliasObjectPtr )
- {
- OSErr anErr = noErr;
- AEDesc aliasDesc = { typeNull, nil };
-
- anErr = OHMakeAliasDescFromFSSpec( fssPtr, &aliasDesc );
- if ( anErr == noErr )
- {
- anErr = CreateObjSpecifier( typeAlias, containerObjPtr, formAbsolutePosition,
- &aliasDesc, false, aliasObjectPtr );
- AEDisposeDesc( &aliasDesc );
- }
-
- return anErr;
- }//end MakeAliasObject
-
- //******************************************************************************
-
- pascal OSErr OHMakeAliasObject( const AliasHandle aliasHandle,
- AEDesc *containerObjPtr,
- AEDesc *aliasObjectPtr )
- {
- OSErr anErr = noErr;
- AEDesc aliasDesc;
-
- anErr = OHMakeAliasDesc( aliasHandle, &aliasDesc );
- if ( anErr == noErr )
- {
- anErr = CreateObjSpecifier( typeAlias, containerObjPtr, formAbsolutePosition,
- &aliasDesc, false, aliasObjectPtr );
- AEDisposeDesc( &aliasDesc );
- }
-
- return anErr;
- }//end MakeAliasObject
-
- //******************************************************************************
-
- pascal OSErr OHMakePropertyObject( const DescType propType,
- AEDesc *containerObjPtr,
- AEDesc *propertyObjPtr )
- {
- OSErr anErr = noErr;
- AEDesc propDesc;
-
- anErr = AECreateDesc( typeType, &propType, sizeof( propType ), &propDesc );
- if ( anErr == noErr )
- {
- anErr = CreateObjSpecifier( cProperty, containerObjPtr, formPropertyID,
- &propDesc, false, propertyObjPtr );
- AEDisposeDesc( &propDesc );
- }
-
- return anErr;
- }//end MakePropertyObject
-
- //******************************************************************************
-
- pascal OSErr OHMakeProcessObject( const ProcessSerialNumber *psnPtr,
- AEDesc *containerObjPtr,
- AEDesc *psnObjPtr )
- {
- OSErr anErr = noErr;
- AEDesc psnDesc;
-
- anErr = AECreateDesc( typeProcessSerialNumber, psnPtr, sizeof( ProcessSerialNumber ), &psnDesc );
- if ( anErr == noErr )
- {
- anErr = CreateObjSpecifier( cProperty, containerObjPtr, formPropertyID,
- &psnDesc, false, psnObjPtr );
- AEDisposeDesc( &psnDesc );
- }
-
- return anErr;
- }//end MakePropertyObject
-
- //******************************************************************************
-
- pascal OSErr OHMakeSelectionObject( const DescType selection,
- AEDesc *containerObjPtr,
- AEDesc *selectionObject )
- {
- OSErr anErr = noErr;
-
- AEDesc selectionDesc = { typeNull, nil };
-
- anErr = AECreateDesc( typeAbsoluteOrdinal, &selection, sizeof( selection ), &selectionDesc );
- if ( anErr == noErr )
- {
- anErr = CreateObjSpecifier( cObject, containerObjPtr, formAbsolutePosition,
- &selectionDesc, false, selectionObject );
- AEDisposeDesc( &selectionDesc );
- }
- return anErr;
- }
-
- //******************************************************************************
-
- pascal OSErr OHMakeIconSuite( const AEDescList *iconFamilyRecPtr,
- Handle *iconSuitePtr )
- {
- OSErr anErr = noErr;
-
- const long iconTypesCnt = 6;
- static DescType iconTypes[] = { typeIconAndMask,
- type8BitIcon,
- type4BitIcon,
- typeSmallIconAndMask,
- typeSmall8BitIcon,
- typeSmall4BitIcon };
-
- AEDescList iconList = { typeNull, nil };
-
- // if ( FinderUsesIconFamily() )
- if ( true )
- {
- anErr = AECoerceDesc( iconFamilyRecPtr, typeAERecord, &iconList );
- }
- else
- {
- iconList = *iconFamilyRecPtr;
- }
-
- if ( anErr == noErr )
- {
- anErr = NewIconSuite( iconSuitePtr );
- if ( anErr == noErr )
- {
- long index;
- AEDesc iconDataDesc = { typeNull, nil };
-
- for ( index = 0; index < iconTypesCnt; index++ )
- {
- anErr = AEGetKeyDesc( &iconList, iconTypes[ index ],
- typeWildCard, &iconDataDesc );
- if ( anErr == noErr )
- {
- anErr = AddIconToSuite( iconDataDesc.dataHandle,
- *iconSuitePtr, iconTypes[ index ] );
- }
- }
- }
- }
- AEDisposeDesc( &iconList );
-
- return anErr;
- }//end OHMakeIconSuite
-
- //******************************************************************************
-
- pascal OSErr MyIconAction( ResType theIconType,
- const Handle *theIcon,
- void *myDataPtr)
- {
- OSErr anErr = noErr;
-
- if ( *theIcon != nil ) // only add the icon if it's really there
- {
- AEDescList *iconFamilyRecPtr = (AEDescList*)myDataPtr;
-
- anErr = AEPutKeyPtr( iconFamilyRecPtr, theIconType, theIconType,
- **theIcon, GetHandleSize( *theIcon ) );
- }
-
- return anErr;
- }//end MyIconAction
-
- //******************************************************************************
-
- pascal OSErr OHMakeIconFamilyRecord( const Handle iconSuite,
- const IconSelectorValue iconSelector,
- AEDescList *iconFamilyRecPtr )
- {
- OSErr anErr = noErr;
- AEDescList iconList = { typeNull, nil };
-
- static IconActionUPP iconActionUPP;
-
- if ( iconActionUPP == nil )
- {
- iconActionUPP = NewIconActionProc( &MyIconAction );
- }
-
- // create a record for the icon family
- anErr = AECreateList( nil, 0, true, &iconList );
-
- if ( anErr == noErr )
- {
- ForEachIconDo( iconSuite, iconSelector,
- iconActionUPP, &iconList );
-
- // if ( FinderUsesIconFamily() )
- if ( true )
- {
- anErr = AECoerceDesc( &iconList, typeIconFamily, iconFamilyRecPtr );
- }
- else
- {
- *iconFamilyRecPtr = iconList;
- }
-
- AEDisposeDesc( &iconList );
- }
-
- return anErr;
- }//end OHMakeIconFamilyRecord
-
- //******************************************************************************
-
- pascal OSErr OHMakePositionList( const Point position,
- AEDescList * posListPtr )
- {
- OSErr anErr = noErr;
-
- anErr = AECreateList( nil, 0, false, posListPtr );
- if ( anErr == noErr )
- {
- anErr = AEPutPtr( posListPtr, 0, typeInteger, &(position.h), sizeof( short ) );
- if ( anErr == noErr )
- {
- anErr = AEPutPtr( posListPtr, 0, typeInteger, &(position.v), sizeof( short ) );
- }
- }
-
- return anErr;
- }//end OHMakePositionList
-
- //******************************************************************************
-
- // *******************************************
- // ***** AddTwoIntListToEvent *****
- // *******************************************
- // Creates an AEList containing 2 integers, and then adds the list to an Apple event.
-
- /*
- OSErr AddTwoIntListToEvent( AppleEvent *theEvent, long param1, long param2 )
- {
- OSErr anErr;
-
- AEDescList paramList;
- anErr = AECreateList( nil, 0, false, ¶mList );
- if ( anErr == noErr )
- {
- anErr = AEPutPtr( ¶mList, 0, typeInteger, ¶m1, sizeof( param1 ) );
- if ( anErr == noErr )
- {
- anErr = AEPutPtr( ¶mList, 0, typeInteger, ¶m2, sizeof( param2 ) );
- if ( anErr == noErr )
- {
- anErr = AEPutParamDesc( theEvent, keyDirectObject, ¶mList );
- }
- }
- }
-
- AEDisposeDesc( ¶mList );
- return ( anErr );
- }// end AddTwoIntListToEvent
-
- */
-